<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Declaring Getopt Rules - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.console.getopt.rules.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.console.getopt.rules.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.console.getopt.introduction.html">Introduction</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.console.getopt.html">Zend_Console_Getopt</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.console.getopt.fetching.html">Fetching Options and Arguments</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.console.getopt.rules" class="section"><div class="info"><h1 class="title">Declaring Getopt Rules</h1></div>
    

    <p class="para">
        The constructor for the <span class="classname">Zend_Console_Getopt</span> class takes
        from one to three arguments. The first argument
        declares which options are supported by your application.
        This class supports alternative syntax forms for declaring the options.
        See the sections below for the format and usage of these syntax forms.
    </p>

    <p class="para">
        The constructor takes two more arguments, both of which are optional.
        The second argument may contain the command-line arguments.
        This defaults to <var class="varname">$_SERVER[&#039;argv&#039;]</var>.
    </p>

    <p class="para">
        The third argument of the constructor may contain an
        configuration options to customize the behavior of
        <span class="classname">Zend_Console_Getopt</span>.
        See <a href="zend.console.getopt.configuration.html#zend.console.getopt.configuration.config" class="link">Adding Configuration</a>
        for reference on the options available.
    </p>

    <div class="section" id="zend.console.getopt.rules.short"><div class="info"><h1 class="title">Declaring Options with the Short Syntax</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Console_Getopt</span> supports a compact syntax similar
            to that used by <acronym class="acronym">GNU</acronym> Getopt (see <a href="http://www.gnu.org/software/libc/manual/html_node/Getopt.html" class="link external">&raquo; http://www.gnu.org/software/libc/manual/html_node/Getopt.html</a>.
            This syntax supports only single-character flags. In a single
            string, you type each of the letters that correspond to flags
            supported by your application. A letter followed by a colon
            character (<em class="emphasis">:</em>) indicates a flag that requires a
            parameter.
        </p>

        <div class="example" id="zend.console.getopt.rules.short.example"><div class="info"><p><b>Example #1 Using the Short Syntax</b></p></div>
            

            <pre class="programlisting brush: php">
$opts = new Zend_Console_Getopt(&#039;abp:&#039;);
</pre>

        </div>

        <p class="para">
            The example above shows using <span class="classname">Zend_Console_Getopt</span>
            to declare that options may be given as <strong class="command">-a</strong>,
            <strong class="command">-b</strong>, or <strong class="command">-p</strong>. The latter flag
            requires a parameter.
        </p>

        <p class="para">
            The short syntax is limited to flags of a single character.
            Aliases, parameter types, and help strings are not supported
            in the short syntax.
        </p>
    </div>

    <div class="section" id="zend.console.getopt.rules.long"><div class="info"><h1 class="title">Declaring Options with the Long Syntax</h1></div>
        

        <p class="para">
            A different syntax with more features is also available. This
            syntax allows you to specify aliases for flags, types of option
            parameters, and also help strings to describe usage to the user.
            Instead of the single string used in the short syntax to declare
            the options, the long syntax uses an associative array as the
            first argument to the constructor.
        </p>

        <p class="para">
            The key of each element of the associative array is a string with
            a format that names the flag, with any aliases, separated by the
            pipe symbol (&quot;<em class="emphasis">|</em>&quot;). Following this series of flag
            aliases, if the option requires a parameter, is an equals symbol
            (&quot;<em class="emphasis">=</em>&quot;) with a letter that stands for the
            <em class="emphasis">type</em> of the parameter:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    &quot;<em class="emphasis">=s</em>&quot; for a string parameter
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    &quot;<em class="emphasis">=w</em>&quot; for a word parameter
                    (a string containing no whitespace)
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    &quot;<em class="emphasis">=i</em>&quot; for an integer parameter
                </p>
            </li>
        </ul>

        <p class="para">
            If the parameter is optional, use a dash (&quot;<em class="emphasis">-</em>&quot;)
            instead of the equals symbol.
        </p>

        <p class="para">
            The value of each element in the associative array is a help string
            to describe to a user how to use your program.
        </p>

        <div class="example" id="zend.console.getopt.rules.long.example"><div class="info"><p><b>Example #2 Using the Long Syntax</b></p></div>
            

            <pre class="programlisting brush: php">
$opts = new Zend_Console_Getopt(
  array(
    &#039;apple|a&#039;    =&gt; &#039;apple option, with no parameter&#039;,
    &#039;banana|b=i&#039; =&gt; &#039;banana option, with required integer parameter&#039;,
    &#039;pear|p-s&#039;   =&gt; &#039;pear option, with optional string parameter&#039;
  )
);
</pre>

        </div>

        <p class="para">
            In the example declaration above, there are three options.
            <strong class="command">--apple</strong> and <strong class="command">-a</strong> are aliases for each
            other, and the option takes no parameter.
            <strong class="command">--banana</strong> and <strong class="command">-b</strong> are aliases for each
            other, and the option takes a mandatory integer parameter.
            Finally, <strong class="command">--pear</strong> and <strong class="command">-p</strong> are aliases
            for each other, and the option may take an optional string parameter.
        </p>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.console.getopt.introduction.html">Introduction</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.console.getopt.html">Zend_Console_Getopt</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.console.getopt.fetching.html">Fetching Options and Arguments</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.console.getopt.html">Zend_Console_Getopt</a></li>
  <li><a href="zend.console.getopt.introduction.html">Introduction</a></li>
  <li class="active"><a href="zend.console.getopt.rules.html">Declaring Getopt Rules</a></li>
  <li><a href="zend.console.getopt.fetching.html">Fetching Options and Arguments</a></li>
  <li><a href="zend.console.getopt.configuration.html">Configuring Zend_Console_Getopt</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>